package com.psp.park.interceptor;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class CommonInterceptor extends HandlerInterceptorAdapter {
	private long startTime;

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		Logger.getLogger(this.getClass()).info("start----------------------------------------------");

		request.setCharacterEncoding("utf-8");
		startTime = System.currentTimeMillis();
		response.setCharacterEncoding("utf-8");
		return super.preHandle(request, response, handler);
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		Logger.getLogger(this.getClass()).info("执行时间：" + (System.currentTimeMillis() - startTime) + "ms");
		Logger.getLogger(this.getClass()).info("end----------------------------------------------");
		super.afterCompletion(request, response, handler, ex);
	}
}